package com.demo.listener;

import com.demo.listener.message.Order;
import com.rabbitmq.client.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 消息监听
 *
 * @author jie.luo
 * @since 2021/3/1
 */
//@Component
public class OrderConsumerListener {

    private static final Logger LOGGER = LoggerFactory.getLogger(OrderConsumerListener.class);

    /**
     * 下单操作
     */
//    @RabbitListener(queues = "order.queue")
    public void orderConsumer(Message message, Channel channel, @Payload Order order) throws IOException {

        long deliveryTag = message.getMessageProperties().getDeliveryTag();

        LOGGER.debug("下单消费消息内容：{} ， deliveryTag: {} ", order, deliveryTag);

        // 手动确认消息
        channel.basicAck(deliveryTag, false);
    }

}
